package com.lemon.secondhandplatform.mode;

import com.lemon.secondhandplatform.util.PhotoUtils;

import java.io.File;
import java.util.Map;

import cn.bmob.v3.BmobObject;
import cn.bmob.v3.datatype.BmobFile;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.UploadFileListener;

/**
 * 商品图片
 */
public class Photo extends BmobObject {

    //图片原名字
    private String oldName;
    //图片上传到服务器的名字
    private String newName;
    //图片的大小
    private Double size;
    //单位
    private String unit;
    //图片格式
    private String suffix;
    //图片文件
    private BmobFile file;
    //商品
    private Good good;

    public Photo(final BmobFile file) {
        this.file = file;

        File localFile = file.getLocalFile();
        oldName = localFile.getName();
        Map map = PhotoUtils.convert(localFile.length());
        size = (Double) map.get("size");
        unit = (String) map.get("unit");
        suffix = oldName.substring(oldName.lastIndexOf(".") + 1);

        file.uploadblock(new UploadFileListener() {
            @Override
            public void done(BmobException e) {

            }
        });
    }

    public String getOldName() {
        return oldName;
    }

    public void setOldName(String oldName) {
        this.oldName = oldName;
    }

    public String getNewName() {
        return newName;
    }

    public void setNewName(String newName) {
        this.newName = newName;
    }

    public Double getSize() {
        return size;
    }

    public void setSize(Double size) {
        this.size = size;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    public BmobFile getFile() {
        return file;
    }

    public void setFile(BmobFile file) {
        this.file = file;
    }

    public Good getGood() {
        return good;
    }

    public void setGood(Good good) {
        this.good = good;
    }

}
